import request from '../axios'
// 申请物料
export function applyGoods (ids, nums, remark, address, unit) {
  const url = '/api/apply/goods'
  const data = {
    ids,
    nums,
    remark,
    address,
    unit,
    Loading: true
  }
  return request.post(url, data)
}

/**
 * 获取物料申请
 * @param id
 */
export function getGoods (id) {
  const url = `/api/apply/goods/${id}`
  return request.get(url)
}

export function listGoods (top, startDate, endDate, cid) {
  const url = '/api/apply/goods'
  const params = { top, startDate, endDate, cid }
  return request.get(url, { params })
}

// 业务申请
export function applyBus (param) {
  const url = '/api/apply/bus/'
  const data = {
    ...param,
    json: true,
    Loading: true
  }
  return request.post(url, data)
}

export function applyLeave (apply, hours) {
  const url = '/api/apply/bus/leave'
  const data = {
    ...apply,
    hours,
    Loading: true
  }
  return request.post(url, data)
}

export function totalHour (start, end) {
  const url = '/api/apply/bus/hour'
  const params = { start, end }
  return request.get(url, { params })
}

// 获取业务
export function getBus (id) {
  const url = `/api/apply/bus/${id}`
  return request.get(url)
}

// 获取业务
export function getBusLeave (id) {
  const url = `/api/apply/bus/leave/${id}`
  return request.get(url)
}

// 考核出差
export function checkBus (id, status, remark) {
  const url = `/api/apply/bus/${id}`
  const data = {
    id,
    status,
    remark,
    Loading: true
  }
  return request.put(url, data)
}

// 考核请假
export function checkBusLeave (id, status, remark) {
  const url = `/api/apply/bus/leave/${id}`
  const data = {
    id,
    status,
    remark,
    Loading: true
  }
  return request.put(url, data)
}

export function listBus (top, startDate, endDate, userId) {
  const url = '/api/apply/bus'
  const params = { top, startDate, endDate, userId }
  return request.get(url, { params })
}

export function listBusLeave (top, startDate, endDate, userId) {
  const url = '/api/apply/bus/leave'
  const params = { top, startDate, endDate, userId }
  return request.get(url, { params })
}

export function sumBus (type) {
  const url = '/api/apply/bus/sum'
  const params = { type }
  return request.get(url, { params })
}

export function sumBusLeave (type) {
  const url = '/api/apply/bus/sum/leave'
  const params = { type }
  return request.get(url, { params })
}

export function options () {
  const url = '/bus/apply/dmz/options'
  return request.get(url)
}

// 费用申请
export function applyCost (apply) {
  const url = '/api/apply/cost/'
  const data = {
    ...apply,
    Loading: true
  }
  return request.post(url, data)
}

// 获取费用申请
export function getCost (id) {
  const url = `/api/apply/cost/${id}`
  return request.get(url)
}

// 审核费用
export function checkCost (id, status, remark) {
  const url = `/api/apply/cost/${id}`
  const data = {
    id,
    status,
    remark,
    Loading: true
  }
  return request.put(url, data)
}

// 审核物料
export function checkGoods (id, status, remark) {
  const url = `/api/apply/goods/${id}`
  const data = {
    id,
    status,
    remark,
    Loading: true
  }
  return request.put(url, data)
}

export function listCost (top, startDate, endDate, cid) {
  const url = '/api/apply/cost'
  const params = {
    startDate, top, endDate, cid
  }
  return request.get(url, { params })
}

// 费用申请
export function applyAdvise (apply) {
  const url = '/api/apply/advise/'
  const data = {
    ...apply,
    Loading: true
  }
  return request.post(url, data)
}

// 获取费用申请
export function getAdvise (id) {
  const url = `/api/apply/advise/${id}`
  return request.get(url)
}

export function listAdvise () {
  const url = '/api/apply/advise'
  return request.get(url)
}

// 获取费用相关统计
export function costSum () {
  const url = '/api/apply/cost/sum'
  return request.get(url)
}

// 统计需要审核
export function costSumCheck () {
  const url = '/api/apply/cost/check/sum'
  return request.get(url)
}

// 获取物料相关统计
export function goodsSum () {
  const url = '/api/apply/goods/sum'
  return request.get(url)
}

// 获取物料相关统计
export function goodsSumCheck () {
  const url = '/api/apply/goods/sum/check'
  return request.get(url)
}
